package com.iplay.thezen.chainOfResponsibility;


/**
 * @author dangwu
 * @since 2021/9/13 6:03 下午
 */
public abstract class Handler {
    private Handler nextHandler;
    public void setNextHandler(Handler nextHandler){
        this.nextHandler = nextHandler;
    }
    protected abstract Level getHandlerLevel();
    protected abstract Response echo(Request request);

    public final Response handleMassage(Request request){
        Response response = null;
        if (this.getHandlerLevel().equals(request.getRequestLevel())){
            response = this.echo(request);
        }else {
            if (this.nextHandler != null){
                response = this.nextHandler.handleMassage(request);
            }else {
                //没有适当的处理者，业务自行处理
            }
        }
        return response;
    }
}
